package ai.people.platform.system.service.impl;

import ai.people.netmon.framework.domain.system.entity.SystemDictData;
import ai.people.platform.dict.service.SysDictDataService;
import ai.people.platform.system.service.SysDictService;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.RequiredArgsConstructor;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 系统字典服务impl
 *
 * @author yuanqinglong
 * @date 2022/3/16 11:41
 */
@Service
@DS("cockroach")
@RequiredArgsConstructor
public class SysDictServiceImpl implements SysDictService {

    private final SysDictDataService sysDictDataService;



    /**
     * 按字典code获取列表
     *
     * @param dictCode 字典code
     * @return {@link List}<{@link SystemDictData}>
     */
    @Trace
    @Override
    @Tags({@Tag(key = "returned",value = "returnedObj"),@Tag(key = "param",value = "arg[0]")})
    public List<SystemDictData> listDictByCode(String dictCode) {
        return sysDictDataService.listDictByCode(dictCode);
    }

    @Override
    public Map<String, List<SystemDictData>> listDictByCodeMulti(List<String> dictTypes) {
        List<SystemDictData> obj = sysDictDataService.listDictByCodeMulti(dictTypes);
        return obj.stream().collect(Collectors.groupingBy(SystemDictData::getDictCode));
    }
}
